home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ansi / txtcap20.zip / TEXTCAP.ASM < prev    next >
Assembly Source File  |  1991-12-05  |  41KB  |  864 lines

  1. ;----------------------------------------------------------------------
  2. ; TEXTCAP is a resident utility which copies a text screen
  3. ; to a file. Activate TEXTCAP by pressing Ctrl-F9 or the hot key
  4. ; specified by /K<number> on the command line. Help by /?.
  5. ; The filename will be SCNxxxxx.TXT. The number part begins with 00000
  6. ; and is incremented by 1 each time TEXTCAP is activated.
  7. ; ---> Authored originally by Tom Kihlken for PC Magazine in 1987   <---
  8. ; ---> Heavily modified by TapirSoft Gisbert W.Selke, 04 Dec 1991   <---
  9. ; amongst others a mini-API via INT 16h, ax=4252h..4254h:
  10. ; 4252h : installation check, responds with 5242h
  11. ; 4253h : removal from memory, responds with segment we used; calling programme
  12. ;         must de-allocate this segment!
  13. ; 4254h : dump text screen now, responds with 5442h
  14. ;-----------------------------------------------------------------------
  15.  
  16. ;-----------------------------------------------------------------------
  17. BIOS_SEG        SEGMENT AT 0040H
  18.  
  19.                 ORG     0017H
  20. KB_FLAG         DB      ?               ;BIOS keyboard shift status
  21.  
  22. BIOS_SEG        ENDS
  23.  
  24. ;=======================================================================
  25. CSEG            SEGMENT
  26.                 Assume  CS:CSEG, DS:CSEG, ES:CSEG
  27.  
  28.                 Org     0080h
  29. CmdLine         Label   Byte                    ; pointer to command line
  30.  
  31.                 ORG     0100H                   ; Beginning for .COM programs
  32. START:          JMP     INITIALIZE              ; Initialization code is at end
  33.  
  34. ;-----------------------------------------------------------------------
  35. ; Data needed by this program
  36. ;-----------------------------------------------------------------------
  37.  
  38. NROWS           Equ     50                      ; max number of lines on screen
  39. NCOLS           Equ     132                     ; max number of columns per line
  40. NBYTES          Equ     NROWS*NCOLS*2           ; length of screen in bytes
  41.  
  42. DosCall         Equ     21h                     ; DOS interrupt number
  43. PrintChar       Equ     02h                     ; DOS function 'print char'
  44. PrintString     Equ     09h                     ; DOS function 'print string'
  45. SetVec          Equ     2500h                   ; DOS function 'set interrupt vector'
  46. Keep            Equ     3100h                   ; DOS function 'stay resident'
  47. GetVec          Equ     3500h                   ; DOS function 'get interrupt vector'
  48. FreeMem         Equ     49h                     ; DOS function 'free memory'
  49. Exec            Equ     4Bh                     ; DOS function 'exec'
  50. ExitCode        Equ     4Ch                     ; exit with error code
  51.  
  52. ChkCode         Equ     4252h                   ; our special installation check
  53. RemoveCode      Equ     4253h                   ; our special request for removal
  54. DumpCode        Equ     4254h                   ; our special request for dumps
  55. InstalledCode   Equ     5242h                   ; footprint 'installed'
  56.  
  57. Tab             Equ     09h                     ; ASCII tab
  58. CR              Equ     0Dh                     ; carriage return
  59. LF              Equ     0Ah                     ; line feed
  60. CtrlZ           Equ     1Ah                     ; end-of-file mark
  61.  
  62. CopyRight       db      CR, 'TEXTCAP 2.0 (c) 1987/91 Ziff Communications Co'
  63.                 db      '/TapirSoft Gisbert W.Selke$', CtrlZ
  64. FileName        db      80 Dup (0)              ; output path and file name
  65. FileNamePtr     dw      FileName                ; pointer to beginning etc.
  66.  
  67. HotKey          db      43h             ; scan code of F9
  68. ShiftMask       db      00000100b       ; shift mask: any Ctrl key
  69. OldInt09        DD      ?       ;Old hardware keyboard interrupt vector
  70. OldInt13        DD      ?       ;Old BIOS disk I/O interrupt vector
  71. OldInt16        DD      ?       ;Old keyboard input interrupt vector
  72. OldInt21        DD      ?       ;Old DOS function interrupt vector
  73. CRT_MODE        DB      ?       ;Current video mode
  74. CRT_ROWS        DB      ?       ;Number of lines on screen
  75. CRT_COLS        DB      ?       ;Number of columns on screen, possibly adjusted
  76. CRT_SIZE        DW      ?       ;Actual screen size in bytes (chars+attributes)
  77. ACTIVE_PAGE     DB      ?       ;Number of active video page
  78. WriteFile       DB      0       ;If=1, need to write to disk
  79. ACTIVE          DB      0       ;Indicates CAPTURE is in use
  80. DOS_Stat        DB      0       ;Current DOS function indicator
  81. Busy_flags      DB      0       ;Bit masked as follows:
  82.                                 ;  1 - DOS function is active
  83.                                 ;  2 - BIOS disk I/O is active
  84.  
  85. ;-----------------------------------------------------------------------
  86. ; CAPTURE reads the screen and stores it in an internal buffer.
  87. ;-----------------------------------------------------------------------
  88.  
  89. CAPTURE         PROC    NEAR
  90.                 Assume  DS:CSEG, ES:BIOS_SEG
  91.  
  92.                 MOV     AH, 0Fh                 ;Get current video mode
  93.                 INT     10h
  94.                 MOV     CRT_COLS, AH            ;Store number of screen columns
  95.                 MOV     CRT_MODE, AL            ;Store video mode
  96.                 MOV     ACTIVE_PAGE, BH         ;Store video page
  97.  
  98.                 XCHG    AH, AL                  ;Number of columns in AL
  99.                 XOR     AH, AH
  100.                 CMP     AX, NCOLS               ;Compare to maximum; may be > 127!
  101.                 JBE     SAVE_COLS               ;Skip if we can handle it
  102.                 MOV     AL, NCOLS               ;Else use adjusted number
  103. SAVE_COLS:      MOV     CRT_COLS, AL            ;Store in CRT_COLS
  104.                 PUSH    AX                      ;Save for a sec
  105.  
  106.                 MOV     DL, 25d                 ;Default number of lines
  107.                 MOV     AL, CRT_MODE            ;Get video mode
  108.                 CMP     AL, 07h                 ;If 80*25 text, then ok
  109.                 JE      SET_SIZE
  110.                 MOV     AX, 1130h               ;Else try to get max line
  111.                 INT     10h                     ; ... in DL
  112.                 INC     DL                      ;Adjust to get # lines
  113.                 CMP     DL, NROWS               ;at most NROWS allowed!
  114.                 JBE     SET_SIZE
  115.                 MOV     DL, NROWS
  116. SET_SIZE:
  117.                 MOV     CRT_ROWS, DL            ;Jot down # lines
  118.                 POP     AX                      ;Get back number of columns
  119.                 MUL     DL                      ;Multiply to get #chars on screen
  120.                 SHL     AX, 1                   ;Double for chars+attributes
  121.                 MOV     CRT_SIZE, AX            ;This many bytes to write!
  122.  
  123.                 MOV     AH, 03h                 ;Cursor pos for this page
  124.                 MOV     BH, ACTIVE_PAGE
  125.                 INT     10h
  126.                 PUSH    DX                      ;Save the cursor location
  127.                 MOV     DI,OFFSET BUFFER        ;DS:DI points to the buffer
  128.                 XOR     DX,DX                   ;Start at row 0, column 0
  129. READ_LOOP:
  130.                 MOV     AH, 02h
  131.                 MOV     BH, ACTIVE_PAGE
  132.                 INT     10h             ;Tell BIOS where the cursor is
  133.                 MOV     BH,ACTIVE_PAGE  ;Get active page from BIOS data
  134.                 MOV     AH,8            ;BIOS function to read character
  135.                 INT     10H             ;Read the character/attribute
  136.  
  137.                 MOV     [DI],AX         ;Put the character in buffer
  138.                 INC     DI              ;Increment the pointer twice
  139.                 INC     DI              ;Since we stored a word
  140.  
  141.                 INC     DL              ;Do the next char in same row
  142.                 CMP     DL,DS:CRT_COLS  ;At the right border yet?
  143.                 JNE     READ_LOOP       ;Do all characters in this row
  144.                 INC     DH              ;Move to next row
  145.                 XOR     DL,DL           ;Back to left edge (Column 0)
  146.                 CMP     DH,DS:CRT_ROWS  ;Done all rows yet?
  147.                 JNE     READ_LOOP       ;Loop until whole screen is read
  148.